package com.rbac.web.model.req;

import com.rbac.web.service.IUserService;
import com.rbac.web.model.PageResult;
import com.rbac.web.model.PageV0;
import com.rbac.web.model.User;
import com.rbac.web.model.res.UserGetListRes;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author gengaoliu
 */
@Schema(description = "用户列表请求参数")
@Data
@EqualsAndHashCode(callSuper = true)
public class UserGetListReq extends PageBase {
  @Schema(description = "名称")
  private String name;

  public PageResult<UserGetListRes> execute(PageV0 pageV0, String name, IUserService userService) {
    PageResult<User> all = userService.query(pageV0, name);
    List<UserGetListRes> list = all.getList().stream().map(UserGetListRes::from).toList();
    return PageResult.of(all.getPage(), all.getSize(), all.getTotal(), list);
  }
}
